#include<bits/stdc++.h>
#define int long long
#define N 400005

using namespace std;

int T, n;
int a[N];
set<int>s;
signed main() {
	freopen("kte.in", "r", stdin);
	freopen("kte.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> T;
	while(T--) {
		int x, ans = 0;
		cin >> x;
		if(s.find(x) != s.end()) s.erase(x);
		else s.insert(x);
		n = 0;
		for(auto x : s) a[++n] = x;
		int L = 0, R = 0, s0 = 0, s1 = 0;
		for(int i = 1, j = n; i < n; i++, j--) {
			s0 += a[i]; s1 += a[j];
			int nowL = s0, nowR = s1 - 1;
			if(nowL > nowR) continue;
			ans += nowR - nowL + 1;
			if(nowL <= R) ans -= (R - nowL + 1);
			L = nowL; R = nowR;
		}
		cout << ans << endl;
	}
	return 0;
}
